package wsi.detect;

import java.io.File;

import org.rygh.core.security.USecurity;
import org.rygh.core.util.UIo;

import wsi.script.AppConfig;

@Deprecated
public class UrlCache {

	public static void cache(String key, String content) {
		if (content == null || content.trim().isEmpty())
			return;

		UIo.saveFile(getFile(key), content);
	}

	public static void delete(String key) {
		File file = getFile(key);

		if (file.exists()) {
			System.out.println("delete cache " + key);
			file.delete();
		}
	}

	public static String fetch(String key) {
		return UIo.readFile(getFile(key));
	}

	private static File getFile(String key) {
		return new File(AppConfig.shared().getCacheFolder(), getFileName(key));
	}

	public static String getFileName(String key) {
		String md5 = USecurity.md5(key);
		String fname = String.format("c_%s.txt", md5);

		return fname;
	}

}
